package com.jiang.daily.Q2043;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/10/27 11:13
 */
class Bank {
    private long[] balance;
    private int n;

    public Bank(long[] balance) {
        this.balance = balance;
        n = balance.length;
    }

    public boolean transfer(int account1, int account2, long money) {
        if (--account1 < n && --account2 < n && balance[account1] >= money) {
            balance[account1] -= money;
            balance[account2] += money;
            return true;
        }
        return false;
    }

    public boolean deposit(int account, long money) {
        if (--account < n) {
            balance[account] += money;
            return true;
        }
        return false;

    }

    public boolean withdraw(int account, long money) {
        if (--account < n && balance[account] >= money) {
            balance[account] -= money;
            return true;
        }
        return false;
    }
}

/**
 * Your Bank object will be instantiated and called as such:
 * Bank obj = new Bank(balance);
 * boolean param_1 = obj.transfer(account1,account2,money);
 * boolean param_2 = obj.deposit(account,money);
 * boolean param_3 = obj.withdraw(account,money);
 */
